@echo off

set SCRIPT=%1
set PRINT=%~dp0%print.vbs


REM echo Applying: %SCRIPT%
cscript //nologo "%PRINT%" "Applying: %SCRIPT%... "


if exist %SCRIPT%.err del %SCRIPT%.err

REM osql -n -E -S %DBSERVER% -d %DBNAME% -i %SCRIPT% -o %SCRIPT%.log
REM findstr /r "[A-Za-z]" %SCRIPT%.log >nul
osql -n -E -S %DBSERVER% -d %DBNAME% -i %SCRIPT% -o %SCRIPT%.log
findstr /r "[A-Za-z]" %SCRIPT%.log >nul
set DBERRCODE=%ERRORLEVEL%

REM type %SCRIPT%.log

if "%DBERRCODE%" == "0" (
	echo FAILED!
	echo.
	echo --------------------------------------------
	echo FATAL: Error running '%SCRIPT%'
	echo.
	type %SCRIPT%.log
	type %SCRIPT%.log > %SCRIPT%.err
	exit /b 1
)

if NOT "%DBERRCODE%" == "0" (
	echo OK
)